import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
# app.config['MAIL_SERVER'] = 'smtp.163.com'
#         app.config['MAIL_PORT'] = 465
#         app.config['MAIL_USERNAME'] = 'webserve337@163.com'
#         app.config['MAIL_PASSWORD'] = 'EUASXMUAZGPNACXX'
#         app.config['MAIL_USE_TLS'] = False
#         app.config['MAIL_USE_SSL'] = True
#         self.mail = Mail(app)


class MyMail:
    # app flask实例
    def __init__(self):
        self.con = smtplib.SMTP_SSL('smtp.163.com', 465)
        self.con.login('webserve337@163.com', 'EUASXMUAZGPNACXX')

    # dest 收信方 head 主题 body 信息内容主题 sender 发送者
    def send(self, dest, head, body, kind='plain', sender='webserve337@163.com'):
        msg = MIMEMultipart()
        msg['Subject'] = Header(head, 'utf-8').encode()
        msg['From'] = sender
        msg['To'] = dest  # 以 ; 分隔 可以批量发送
        msg.attach(MIMEText(body, kind, 'utf-8'))  # kind 调整文本内容类型
        self.con.sendmail(sender, dest, msg.as_string())
